﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;

namespace JULONG.WEB.Library.Account
{
    public class routeForFilter
    {
        public routeItem area { get; set; }
        public routeItem controller { get; set; }
        public routeItem action { get; set; }

        public routeForFilter()
        {

        }

        public routeForFilter(RouteData dict)
        {
            this.controller = dict.Values["controller"].ToTryString();
            this.action = dict.Values["action"].ToTryString();
            var area = dict.DataTokens;
            if (area.ContainsKey("area"))
            {
                this.area = area["area"].ToTryString();
            }
            else
            {
                this.area = new routeItem(null);
            }

        }

        /// <summary>
        /// 根据string 构造
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="action"></param>
        /// <param name="area"></param>
        public routeForFilter(string action, string controller, string area = null)
        {
            this.controller = controller;
            this.action = action;
            this.area = area;
        }


        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }


        /// <summary>
        /// == 运算符重载
        /// </summary>
        /// <param name="r1"></param>
        /// <param name="r2"></param>
        /// <returns></returns>
        public static bool operator ==(routeForFilter left, routeForFilter right)
        {
            if (Equals(left, right))
                return true;

            if (left.action != right.action)
                return false;

            if (left.controller != right.controller)
                return false;

            if (left.area != right.area)
                return false;

            return true;
        }

        /// <summary>
        /// != 运算符重载
        /// </summary>
        /// <param name="r1"></param>
        /// <param name="r2"></param>
        /// <returns></returns>
        public static bool operator !=(routeForFilter left, routeForFilter right)
        {
            if (Equals(left, right))
                return false;

            if (left.action != right.action)
                return true;

            if (left.controller != right.controller)
                return true;

            if (left.area != right.area)
                return true;

            return false;
        }

    }
}
